//配置信息
/**
 * @openapi
 * tags:
 * - name: config
 *   description: 配置信息
 */
const router = require("express-promise-router")(); //允许路由返回promise,方便使用async/await
const qiniu = require("../services/qiniu");
const _config = require("../config/config");



/**
 * @openapi
 * /config/reconfirm:
 *   get:
 *     tags:
 *     - word
 *     summary: word插件获取实验报告是否需要二次确认
 *     responses:
 *       200:
 *         description: 返回配置信息
 */
//获取实验报告是否需要二次确认（报告插件中使用）
router.get('/reconfirm', async (req, res) => {
    const config=require("../config/config");
    res.send(!!config.reconfirm);
});

/**
 * @openapi
 * /config:
 *   get:
 *     tags:
 *     - config
 *     summary: 配置信息
 *     responses:
 *       200:
 *         description: 返回配置信息
 */
router.get('/', async (req, res) => {
    const upload_token=qiniu.getUploadToken();
    const _config=require("../config/config");
    const config={
        upload_token,
        is_test_mode:_config.is_test_mode,
        is_open_auto_choose:_config.is_open_auto_choose,
        is_open_msg:_config.is_open_msg,
        is_open_classname:_config.is_open_classname,
        is_open_chachong:_config.is_open_chachong,
        is_open_paike:_config.is_open_paike,
        domain:_config.domain,
        fileserver:_config.fileserver,
        qiniu_upload_url:_config.qiniu_upload_url,
        qiniu_domain:_config.qiniu_domain,
        college:_config.college,
        template_file:_config.template_file,
        is_open_fujian:_config.is_open_fujian,
        is_open_virtual_room:_config.is_open_virtual_room,
        is_open_refresh_export_reports:_config.is_open_refresh_export_reports,
        is_open_weixin_register:_config.is_open_weixin_register,
        is_use_xcx:_config.is_use_xcx,
        categorys:_config.categorys
    };
    const text="var runtimeConfig="+JSON.stringify(config);
    res.send(text);
});

/**
 * @openapi
 * /config/is_open_msg:
 *   get:
 *     tags:
 *     - msg
 *     summary: 短信功能是否开启
 *     responses:
 *       200:
 *         description: 返回短信功能开关状态
 */
//获取短信功能开关状态
router.get('/is_open_msg', async (req, res) => {
    const config=require("../config/config");
    //console.log('config.is_open_msg',config.is_open_msg);
    res.send(!!config.is_open_msg);
});

/**
 * @openapi
 * /config/is_open_classname:
 *   get:
 *     tags:
 *     - msg
 *     summary: 注册必填班级字段是否开启
 *     responses:
 *       200:
 *         description: 返回班级字段开关状态
 */
//获取班级字段开关状态
router.get('/is_open_classname', async (req, res) => {
    const config=require("../config/config");
    res.send(!!config.is_open_classname);
});

/**
 * @openapi
 * /config/is_open_chachong:
 *   get:
 *     tags:
 *     - msg
 *     summary: 查重功能是否开启
 *     responses:
 *       200:
 *         description: 返回查重功能开关状态
 */
//获取班级字段开关状态
router.get('/is_open_chachong', async (req, res) => {
    const config=require("../config/config");
    res.send(!!config.is_open_chachong);
});


module.exports = router;